/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.io.fasta.parser;

import phoside.io.fasta.parser.DefaultHeaderParser;

import phoside.util.StaticFinalValues;

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author gjj
 */
public class DefaultPhosphoHeaderParser
        extends DefaultHeaderParser
        implements PhosphoHeaderParser {
    
    public DefaultPhosphoHeaderParser(final PhosphoHeaderRule rule) {
        super(rule);
    }
   
    public Set<Integer> getSites() {
        String strsites = (String)getField(StaticFinalValues.SITES);
        if (strsites==null) {
            return null;
        }

        String[] strs = strsites.split(((PhosphoHeaderRule)rule).getSitesDelimitor());
        Set<Integer> sites = new HashSet<Integer>(strs.length);
        for (String s : strs) {
            s = s.trim();
            if (s.length()>0) {
                sites.add(Integer.parseInt(s)-1);
            }
        }

        return sites;
    }

}
